import { defineStore } from 'pinia'
import { ref } from 'vue'

// 用户模块
export const useUserStore = defineStore(
  'OrangeCloudLibrary',
  () => {
    const userInfo = ref({
      id: 0,
      name: '',
      role: '',
    })
    const setUserInfo = (info) => {
      userInfo.value = info
    }
    const getUserInfo = () => {
      return userInfo.value
    }
    const removeUserInfo = () => {
      userInfo.value = {
        id: 0,
        name: '',
        role: ''
      }
    }
    const isLogin = () => {
      return userInfo.value.id !== 0 && userInfo.value.role !== '' && userInfo.value.name !== ''
    }
    return {
      userInfo,
      setUserInfo,
      getUserInfo,
      removeUserInfo,
      isLogin
    }
  },
  {
    persist: true // 持久化
  }
)
